
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="register-container">
        <h2>注册</h2>
        <form action="#" method="post">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" required>
            </div>

            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required>
            </div>

            <button type="submit">注册</button>
        </form>
    </div>
</body>
</html>

<script>
    document.getElementById("submit").onclick = function() {
        const username = document.getElementById("username").value;
        const password = document.getElementById("password").value;

        const url = "http://localhost:8080/register";
        const data = {
            username: username,
            password: password
        }
        axios.post(url, data)
        .then(response => {
            if (response.data.code === 200) {
                alert("注册成功");
                window.location.href = "http://localhost:8080/login.html";
            } else {
                alert("注册失败");
            }
        })
     }
</script>

